package com.xiaoyi.intentsdklibrary.SDK.FloatView;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import com.lkx.liandianqinew.R;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.xiaoyi.intentsdklibrary.Utils.StateBarUtil;
import java.text.DecimalFormat;

public class CirCleViewSDK {
    private static final CirCleViewSDK ourInstance = new CirCleViewSDK();
    private ImageView mCirclView;
    private Handler mHandler;
    private WindowManager.LayoutParams mParams;
    private Runnable mR;
    private WindowManager mWindowManager;

    public static CirCleViewSDK getInstance() {
        return ourInstance;
    }

    private CirCleViewSDK() {
    }

    public void init(Context context) {
        try {
            if (this.mWindowManager == null) {
                this.mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                ImageView imageView = new ImageView(context);
                this.mCirclView = imageView;
                imageView.setImageResource(R.drawable.wave);
                WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
                this.mParams = layoutParams;
                layoutParams.flags = 152;
                this.mParams.format = -3;
                if (Build.VERSION.SDK_INT >= 26) {
                    this.mParams.type = 2038;
                } else {
                    this.mParams.type = 2003;
                }
                this.mParams.gravity = 8388659;
                this.mParams.x = 0;
                this.mParams.y = 0;
                this.mParams.width = 100;
                this.mParams.height = 100;
                this.mWindowManager.addView(this.mCirclView, this.mParams);
                ImageView imageView2 = this.mCirclView;
                if (imageView2 != null) {
                    imageView2.setVisibility(View.GONE);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void show(Context context, int i, int i2, int i3) {
        try {
            if (ActionNormalSDK.getInstance().isScreenPortrait(context)) {
                this.mParams.x = i - 50;
                this.mParams.y = (i2 - 50) - StateBarUtil.getStatusBarHeight(context);
            } else {
                try {
                    if (Float.parseFloat(new DecimalFormat("0.00").format((double) (((float) context.getResources().getDisplayMetrics().widthPixels) / ((float) context.getResources().getDisplayMetrics().heightPixels)))) >= 2.0f) {
                        this.mParams.x = (i - 50) - StateBarUtil.getStatusBarHeight(context);
                        this.mParams.y = i2 - 50;
                    } else {
                        this.mParams.x = i - 50;
                        this.mParams.y = i2 - 50;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    this.mParams.x = i - 50;
                    this.mParams.y = i2 - 50;
                }
            }
            this.mParams.width = 100;
            this.mParams.height = 100;
            this.mWindowManager.updateViewLayout(this.mCirclView, this.mParams);
            this.mCirclView.setVisibility(View.VISIBLE);
            this.mCirclView.postDelayed(new Runnable() {
                public void run() {
                    CirCleViewSDK.this.mCirclView.setVisibility(View.GONE);
                }
            }, (long) i3);
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    public void hide() {
        try {
            this.mCirclView.setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
